<?php

class UserLogin extends Controller
{

    function __construct()
    {
        /*
         * 避免子类的构造函数覆盖父类的构造函数
         */
        parent::__construct();
        /*
         * 其它自定义操作
         */
    }

    /**
     * 获取用户列表
     */
    function userLogin($requestPayload)
    {

        // 获取前端传入的用户名密码
        $username = $_POST['username'] ?? '';
        $password = $_POST['password'] ?? '';

        //Medoo框架
        $list = $this->databaseMedoo->select('user', "*",[
            "AND" => [
                "username" => $username,
                "password" => $password
            ]
        ]);

        if($list){
            //返回
            $data['status'] = 200;
            $data['message'] = '成功';
            $data['data'] = $list;
            return $data;
        }else{
            //返回
            $data['status'] = 404;
            $data['message'] = '登录失败，用户名或密码错误';
            $data['data'] = null;
            return $data;
        }
                
    }
}
